<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/bootstrap-responsive.css" />
        <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/style.css" />
        <script type="text/javascript" src="__PUBLIC__/Js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/Js/jquery.sorted.js"></script>
        <script type="text/javascript" src="__PUBLIC__/Js/bootstrap.js"></script>
        <script type="text/javascript" src="__PUBLIC__/Js/ckform.js"></script>
        <script type="text/javascript" src="__PUBLIC__/Js/common.js"></script>
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }

            @media (max-width: 980px) {
                /* Enable use of floated navbar text */
                .navbar-text.pull-right {
                    float: none;
                    padding-left: 5px;
                    padding-right: 5px;
                }
            }


        </style>
    </head>
    <body>
        <form action="{:U('Emp/add')}" method="post" class="definewidth m20" onsubmit="return sure();" enctype="multipart/form-data">
            <table class="table table-bordered table-hover definewidth m10">
                <tr>
                    <td width="10%" class="tableleft">登录ID</td>
                    <td><input type="text" name="loginid" id="loginid"/><span style="display:none; color: #FF0000;">员工名已存在</span></td>
                </tr>
                <tr>
                    <td width="10%" class="tableleft">员工姓名</td>
                    <td><input type="text" name="empname" id="empname"/></td>
                </tr>
				<tr>
                    <td width="10%" class="tableleft">员工头像</td>
                    <td><input type="file" name="emp_pic" id="emp_pic"/></td>
                </tr>
				<tr>
                    <td width="10%" class="tableleft">员工性别</td>
                    <td>
						<input type="radio" name="sex" id="sex" value="0"/>未选
						<input type="radio" name="sex" id="sex" value="1"/>女
						<input type="radio" name="sex" id="sex" value="2"/>男
					</td>
                </tr>
				<tr>
                    <td width="10%" class="tableleft">员工年龄</td>
                    <td><input type="text" name="age" id="age"/></td>
                </tr>
				<tr>
                    <td width="10%" class="tableleft">员工电话</td>
                    <td><input type="text" name="phone" id="phone"/></td>
                </tr>
				<tr>
                    <td width="10%" class="tableleft">员工类型</td>
                    <td><input type="text" name="emp_type" id="emp_type"/></td>
                </tr>
                <tr>
                    <td class="tableleft">密码</td>
                    <td><input type="password" name="password" id="password"/></td>
                </tr>
                </tr>
                <tr>
                    <td class="tableleft"></td>
                    <td>
                        <button type="submit" class="btn btn-primary" type="button">添加</button>&nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
<script>
    var usernameIsOk = false;
    $(function () {
        $('#backid').click(function () {
            window.location.href = "{:U('Emp/emplist')}";
        });
        $('#loginid').blur(function () {
            var times = (new Date()).valueOf();
            var loginid = $.trim($(this).val());
            if (!loginid) {
                return;
            }
            $.post('__APP__/Emp/find', {loginid: loginid}, function (data) {
                if (data == 1) {
                    usernameIsOk = false;
                    $('#loginid').next().css('display', "inline-block");
                } else {
                    usernameIsOk = true;
                    $('#loginid').next().css('display', "none");
                }
            });
        });
    });
    function sure() {
        var username = $('#empname').val();
        if (!username) {
            alert('用户名不能为空');
            return false;
        }
        if (!usernameIsOk) {
            alert('用户名已存在');
            $("#empname").val('');
            return false;
        }
        var password = $('#password').val();
        if (!password) {
            alert('密码不能为空');
            return false;
        }
    }
</script>